package com.xiaoyu.lanling.feature.board

import android.os.Bundle
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.activity.base.AppCompatToolbarActivity
import com.xiaoyu.lanling.feature.board.fragment.GoddessWrapperFragment
import com.xiaoyu.lanling.feature.board.fragment.RichWrapperFragment
import com.xiaoyu.lanling.router.Router
import com.xiaoyu.lanling.view.FragmentAdapter
import com.xiaoyu.lanling.view.OnShowFragment
import com.xiaoyu.lanling.widget.tablayout.ScaleTabLayoutUtils
import kotlinx.android.synthetic.main.activity_board.*

class BoardActivity : AppCompatToolbarActivity() {

    private val fragmentList: MutableList<OnShowFragment> = mutableListOf()

    override fun onCreateSafelyAfterAppFinishInit(savedInstanceState: Bundle?) {
        setTranslucent()
        setContentView(R.layout.activity_board)
        initData()
        initBind()
    }

    private fun initBind() {
        back.setOnClickListener { finish() }
        board_rule.setOnClickListener { Router.instance.gotoBoardRuleActivity(this) }
    }

    private fun initData() {
        // 女神榜
        val goddessWrapperFragment = GoddessWrapperFragment()

        // 富豪榜
        val richWrapperFragment = RichWrapperFragment()

        fragmentList.add(goddessWrapperFragment)
        fragmentList.add(richWrapperFragment)

        val titles = listOf(getString(R.string.board_girl_board), getString(R.string.board_rich_board))
        ScaleTabLayoutUtils.createScaleTabLayout(toolbar_tab_layout, rank_view_pager, titles, false)

        val fragmentAdapter = FragmentAdapter(supportFragmentManager, fragmentList, titles)
        rank_view_pager.offscreenPageLimit = fragmentList.size
        rank_view_pager.currentItem = 0
        rank_view_pager.adapter = fragmentAdapter
    }
}